package com.fanghaoran.view.manager;

import com.fanghaoran.entity.Users;

import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * @Author: win11
 * @Date: 2023/03/27/22:26
 * @Description: 自定义表格模式
 */
public class UserInfoTableModel extends AbstractTableModel {
    private final String[] columnNames = { "id", "用户名", "密码", "salt","手机号","昵称","性别","个性签名","是否被拉黑(0/1)" };
    private final List<Users> userList;

    public UserInfoTableModel(List<Users> userList) {
        this.userList = userList;
    }

    @Override
    public int getRowCount() {
        return userList.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Users user = userList.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return user.getId();
            case 1:
                return user.getUsername();
            case 2:
                return user.getPassword();
            case 3:
                return user.getSalt();
            case 4:
                return user.getTelephone();
            case 5:
                return user.getNickname();
            case 6:
                return user.getGender();
            case 7:
                return user.getSignature();
            case 8:
                return user.getBlocked();
            default:
                return null;
        }
    }


    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }
}
